var RelativeJobSelector = {
	getView : function(d, c) {
		var a = this.initPanel(c);
		var b = new Ext.Window({
			id : "RelativeJobSelectorWin",
			title : "相对岗位选择器",
			iconCls : "menu-relativeJob",
			width : 630,
			minWidth : 400,
			height : 430,
			minHeight : 430,
			maximizable : true,
			layout : "fit",
			border : false,
			items : [ a ],
			modal : true,
			buttonAlign : "center",
			buttons : [
					{
						iconCls : "btn-ok",
						text : "确定",
						handler : function() {
							var g = "";
							var j = "";
							if (c == null || c == true) {
								var h = Ext.getCmp(
										"relativeJobSelectorTreePanel")
										.getSelectionModel().getSelectedNode();
								if (h != null && h.id > 0) {
									g = h.id;
									j = h.text;
								}
							} else {
								var e = Ext.getCmp(
										"selectedRelativeJobGridPanel")
										.getStore();
								for (var f = 0; f < e.getCount(); f++) {
									g += e.getAt(f).data.jobId + ",";
									j += e.getAt(f).data.jobName + ",";
								}
								g = g.substring(0, g.length - 1);
								j = j.substring(0, j.length - 1);
							}
							if (d != null) {
								d.call(this, g, j);
							}
							b.close();
						}
					}, {
						text : "取消",
						iconCls : "btn-cancel",
						handler : function() {
							b.close();
						}
					} ]
		});
		return b;
	},
	initPanel : function(f) {
		var d = f != null && f == true ? "center" : "west";
		var e = new Ext.tree.TreePanel({
			id : "relativeJobSelectorTreePanel",
			layout : "form",
			region : d,
			collapsible : true,
			autoScroll : true,
			split : true,
			width : 200,
			title : "相对岗位列表",
			tbar : new Ext.Toolbar({
				items : [ {
					xtype : "button",
					iconCls : "btn-refresh",
					text : "刷新",
					handler : function() {
						e.root.reload();
					}
				}, {
					xtype : "button",
					text : "展开",
					iconCls : "btn-expand",
					handler : function() {
						e.expandAll();
					}
				}, {
					xtype : "button",
					text : "收起",
					iconCls : "btn-collapse",
					handler : function() {
						e.collapseAll();
					}
				} ]
			}),
			loader : new Ext.tree.TreeLoader({
				url : __ctxPath + "/system/treeLoadRelativeJob.do"
			}),
			root : new Ext.tree.AsyncTreeNode({
				expanded : true
			}),
			rootVisible : false,
			listeners : {
				"dblclick" : this.nodeDBLClick
			}
		});
		var g = new Ext.grid.CheckboxSelectionModel();
		var a = new Ext.grid.EditorGridPanel({
			id : "selectedRelativeJobGridPanel",
			title : "已选相对岗位",
			layout : "form",
			region : "center",
			width : "100%",
			autoWidth : "100%",
			height : "100%",
			autoHeight : "100%",
			border : false,
			autoScroll : true,
			viewConfig : {
				forceFit : true,
				enableRowBody : false,
				showPreview : false
			},
			store : new Ext.data.ArrayStore({
				fields : [ "jobId", "jobName" ]
			}),
			trackMouseOver : true,
			sm : g,
			columns : [ g, new Ext.grid.RowNumberer(), {
				header : "jobId",
				dataIndex : "jobId",
				hidden : true
			}, {
				header : "岗位名称",
				dataIndex : "jobName"
			} ]
		});
		a.addListener("dblclick", function(k) {
			var k = Ext.getCmp("selectedRelativeJobGridPanel");
			var h = k.getStore();
			var l = k.getSelectionModel().getSelections();
			for (var j = 0; j < l.length; j++) {
				k.stopEditing();
				h.remove(l[j]);
			}
		});
		var c = new Ext.Panel({
			layout : "border",
			region : "center",
			width : "100%",
			height : "100%",
			border : false,
			autoScroll : true,
			items : [ new Ext.Panel({
				region : "west",
				frame : true,
				width : 40,
				layout : {
					type : "vbox",
					pack : "center",
					align : "stretch"
				},
				defaultType : "button",
				items : [ {
					iconCls : "add-all",
					text : "",
					scope : this,
					handler : this.addAll
				}, {
					iconCls : "rem-all",
					text : "",
					scope : this,
					handler : this.removeAll
				} ]
			}), {
				region : "center",
				autoScroll : true,
				items : [ a ]
			} ]
		});
		var b = new Ext.Panel({
			layout : "border",
			region : "center",
			autoScroll : true,
			border : false,
			anchor : "98%,98%",
			items : [ e ]
		});
		if (f != null && f == false) {
			b.add(c);
			b.doLayout();
		}
		return b;
	},
	nodeDBLClick : function(f) {
		if (f != null && f.id > 0) {
			var d = Ext.getCmp("selectedRelativeJobGridPanel");
			var b = d.getStore();
			var g = true;
			for (var c = 0; c < b.getCount(); c++) {
				if (b.getAt(c).data.jobId == f.id) {
					g = false;
					break;
				}
			}
			if (g) {
				var e = {
					jobId : f.id,
					jobName : f.text
				};
				var a = new b.recordType(e);
				d.stopEditing();
				b.add(a);
			}
		}
	},
	addAll : function() {
		var a = Ext.getCmp("relativeJobSelectorTreePanel");
		var e = Ext.getCmp("selectedRelativeJobGridPanel");
		var g = a.getSelectionModel().getSelectedNode();
		if (g != null && g.id > 0) {
			var c = e.getStore();
			var h = true;
			for (var d = 0; d < c.getCount(); d++) {
				if (c.getAt(d).data.jobId == g.id) {
					h = false;
					break;
				}
			}
			if (h) {
				var f = {
					jobId : g.id,
					jobName : g.text
				};
				var b = new c.recordType(f);
				e.stopEditing();
				c.add(b);
			}
		}
	},
	removeAll : function() {
		var c = Ext.getCmp("selectedRelativeJobGridPanel");
		var d = c.getSelectionModel().getSelections();
		var a = c.getStore();
		for (var b = 0; b < d.length; b++) {
			c.stopEditing();
			a.remove(d[b]);
		}
	}
};